{include file="public/header" select="0" /}
<body class="bgc">
<div class="header">
    <i class="layui-icon layui-icon-left" onclick="goBack()"></i> 支付订单
</div>
<div class="pay-news flex-center">
    <p>实付金额</p>
    <div>￥<span>{$info.real_amount}</span></div>
</div>
<form action="{:url('order/confirmPayment')}" method="post" class="form">
<input type="hidden" name="id" value="{$info.id}">
<ul class="pay-list">
    <li>
        <label for="check1">
            <p class="flex-center">
                <img src="/static/index/img/icon5.png" alt="">
            </p>
            <p class="center">{:get_pay_way('balance')}</p>
            <img src="/static/index/img/icon7.png" alt="" class="check">
        </label>
        <input type="radio" hidden id="check1" name="pay_way" value="balance" checked>
    </li>
</ul>
<p class="save save-fixed">确认支付</p>
<div class="model">
    <div class="pay-mdl">
        <p class="flex-center cancel">
            <img src="/static/index/img/icon54.png" alt="">
        </p>
        <div class="pay-mdl-news">
            <div>请输入支付密码</div>
            <p class="price">￥<span>{$info.real_amount}</span></p>
            <p>实付金额</p>
            <input type="password" name="pay_password" id="pay_password" lay-verify="required" lay-reqtext="请输入支付密码" placeholder="请输入支付密码">
            <button class="btn payment" lay-submit lay-filter="save" formObj=".form">确认支付</button>
        </div>
    </div>
</div>
</form>
{include file="public/footer" select="0" /}
<script src="/static/index/js/order.js"></script>
<script>
    $(function () {
        $('.pay-list input').click(function() {
            $(this).siblings('label').find('.check').attr('src', '/static/index/img/icon7.png')
            $(this).parent().siblings().find('.check').attr('src', '/static/index/img/icon6.png')
        });

        var os = true;
        $('.save-fixed').click(function() {
            var pay_way = $("input[name='pay_way']:checked").val();
            if (!pay_way) {
                layer.msg('请选择支付方式');
                return false;
            }
            if (pay_way === 'wechat' || pay_way === 'alipay') {
                submitObj();
            } else {
                $('.model').show();
            }
        });

        $('.cancel').click(function() {
            $('.model').hide()
        });


        $(".payment").click(function () {
            submitObj();
        });

        function submitObj() {
            if (os !== true) return false;
            $('.payment').attr('disabled', true);
            os = false;
            layer.load();
            formObj = $('.form');
            url = formObj.attr('action');
            $.ajax({
                type: 'POST',
                url: url,
                data: formObj.serialize(),
                dataType: "json",
                success: function (data) {
                    layer.closeAll();
                    if(data.code < 1){
                        os = true;
                        layer.msg(data.msg);
                        $('.payment').removeAttr('disabled');
                        return false;
                    }
                    payment(data);
                    return false;
                },
                error() {
                    layer.closeAll();
                    $('.payment').removeAttr('disabled');
                }
            });
            return false;
        }
    })
</script>
</body>
</html>